package com.mgface.mrmdb.msgpack;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.msgpack.MessagePack;
import org.msgpack.packer.Packer;
import org.msgpack.unpacker.Unpacker;

public class Main2 {
	public static void main(String[] args) throws IOException {
		MyMessage src1 = new MyMessage();
        src1.name = "msgpack";
        src1.version = 0.6;
        MyMessage src2 = new MyMessage();
        src2.name = "muga";
        src2.version = 10.0;
        MyMessage src3 = new MyMessage();
        src3.name = "frsyukik";
        src3.version = 1.0;
        
        MessagePack msgpack = new MessagePack();
        // Serialize
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Packer pack = msgpack.createPacker(out);
        pack.write(src1);
        pack.write(src2);
        pack.write(src3);
        byte[] serialize = out.toByteArray();
        //Deserialize
        ByteArrayInputStream in = new ByteArrayInputStream(serialize);
        Unpacker unpacker = msgpack.createUnpacker(in);
        MyMessage dst1= unpacker.read(MyMessage.class);
        MyMessage dst2= unpacker.read(MyMessage.class);
        MyMessage dst3= unpacker.read(MyMessage.class);
        System.out.println(dst1+"|"+dst2+"|"+dst3);
	}

}
